#!/usr/bin/python
'''This module extends Alignment class as Bucket class.

This has some useful features specific to the task at hand.
'''

from alignment import Alignment
from sequence import Sequence

class Bucket(Alignment):
    
    def __init__(self, seq=''):
        """Initialise Bucket with either a sequence, or with no element."""
        if seq:
            self.sequences = []
            (self.sequences).append(seq)
        else:
            self.sequences = []
        
    def qualify(self, seq, d):
        """See whether a particular sequence could belong to this bucket or not.
        Returns True if it does, False otherwise.
        """

        for current in self.sequences:
            # reset the distance between current and seq
            dist = 0

            for i in xrange(len(current)):
                if current[i]!= seq[i]:
                    dist += 1

            if dist > d:
                return False
            
        return True
        

if __name__ == '__main__':
    buc = Bucket("atggt")
    buc.add("acggt")
    #buc.add("aagtgtat")
    #print buc.sequences
    print buc.qualify("atcct", 2)

